<template>
	<view class="">
		<u-navbar :is-back="false" title="">
			<view class="slot-wrap">
				<text class="u-flex-1"></text>
				<text class="u-font-34">{{title}}</text>
				<text class="u-flex-1 u-text-right"><text v-if="edit" @click="changeEdit">{{edit}}</text></text>
			</view>
		</u-navbar>
		<view class="u-flex-col">
			<swiper class="" :style="{height: swiperHeight+'px'}" disable-touch :current="current">
				<swiper-item>
					<w-shop-home class="swiper-item"></w-shop-home>
				</swiper-item>
				<swiper-item>
					<w-shop-class class="swiper-item"></w-shop-class>
				</swiper-item>
				<swiper-item>
					<w-shop-car :edit='edit' class="swiper-item" @goHome="change(0)"></w-shop-car>
				</swiper-item>
				<swiper-item>
					<w-shop-mine class="swiper-item"></w-shop-mine>
				</swiper-item>
			</swiper>
			<u-tabbar height='100rpx' active-color='#ae81ff' inactive-color='#b8b8b8' v-model="current" :list="list" @change='change'>
			</u-tabbar>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState(['shopIndex']),
			swiperHeight() {
				return uni.getSystemInfoSync().screenHeight - uni.getSystemInfoSync().statusBarHeight - 50 - uni.upx2px(100)
			}
		},
		data() {
			return {
				list: [
					{
						iconPath: "/static/shome.png",
						selectedIconPath: "/static/shome1.png",
						text: '首页',
						customIcon: false,
					},
					{
						iconPath: "/static/ssearch.png",
						selectedIconPath: "/static/ssearch1.png",
						text: '分类',
						customIcon: false,
					},
					{
						iconPath: "/static/scar.png",
						selectedIconPath: "/static/scar1.png",
						text: '购物车',
						customIcon: false,
					},
					{
						iconPath: "/static/smine.png",
						selectedIconPath: "/static/smine1.png",
						text: '我的',
						customIcon: false,
					},
				],
				current: 0,
				title:'首页',
				edit:''
			}
		},
		onTabItemTap(e) {
			uni.hideTabBar()
		},
		onShow() {
			this.change(this.shopIndex)
		},
		methods: {
			changeEdit(){
				if(this.edit=='编辑'){
					this.edit='完成'
				}else{
					this.edit='编辑'
				}
			},
			change(index) {
				this.$store.commit('setShopIndexm',index)
				this.current = index
				this.edit = ''
				switch (index) {
					case 0:
						this.title = '首页'
						break;
					case 1:
						this.title = '分类'
						break;
					case 2:
						this.title = '购物车'
						this.edit = '编辑'
						break;
					case 3:
						this.title = '我的'
						break;
					default:
						break;
				}
			}
		}
	}
</script>

<style>
</style>

<style lang="scss" scoped>
	.slot-wrap {
		display: flex;
		align-items: center;
		/* 如果您想让slot内容占满整个导航栏的宽度 */
		flex: 1;
		/* 如果您想让slot内容与导航栏左右有空隙 */
		padding: 0 30rpx;
	}
	.swiper-item {
		height: 100%;
	}
</style>
